# 二分类乳腺癌数据集
from sklearn.datasets import load_breast_cancer
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
import pandas as pd

data = load_breast_cancer()
# data = pd.concat([pd.DataFrame(data.data), pd.DataFrame(data.target)], axis=1)
# print(data)
trainX, testX, trainY, testY = train_test_split(data.data, data.target, train_size=0.3, random_state=20)

dtf = DecisionTreeClassifier(criterion="entropy", max_depth=5, splitter="random", random_state=20)
dtf.fit(trainX, trainY)
score = dtf.score(testX, testY)
print(score)
score_ = cross_val_score(dtf, trainX, trainY, cv=10).mean()
print(score_)
# from sklearn.model_selection import GridSearchCV
#
# params = {"max_depth": [*range(1, 10)]
#     , "splitter": ('best', 'random')
#     , "criterion": ('gini', 'entropy')
#           }
# gscv = GridSearchCV(dtf, params, cv=10)
# gscv.fit(trainX, trainY)

# print(gscv.best_params_)
# print(gscv.best_score_)
